package com.igeek.d0619.test1;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @Author: zhiyu
 * @Date:17:07
 * @DESC:
 */
public class Test {
    public static void main(String[] args) {
        Class<BookStore> storeClass = BookStore.class;
        //获取属性集合
        Field[] declaredFields = storeClass.getDeclaredFields();
        System.out.println("获取BookStore类中的属性上面的注解 以及 属性信息");
        for (Field field:declaredFields) {
            if (field.isAnnotationPresent(Book.class)){
                Book book = field.getDeclaredAnnotation(Book.class);
                System.out.println("book.value() = " + book.value());
                System.out.println("book.price() = " + book.price());
                System.out.println("book.authors() = " + Arrays.toString(book.authors()));
            }
        }
        //获取方法集合
        Method[] methods = storeClass.getMethods();
        System.out.println("获取BookStore类中的方法上面的注解 以及 属性信息");
        for (Method method:methods) {
            if (method.isAnnotationPresent(Book.class)){
                Book book = method.getDeclaredAnnotation(Book.class);
                System.out.println("book.value() = " + book.value());
                System.out.println("book.price() = " + book.price());
                System.out.println("book.authors() = " + Arrays.toString(book.authors()));
            }
        }
    }
}
